<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * guestbook frontpage
 */

require_once('lib.php');
require_once('guestbook_form.php');

defined('MOODLE_INTERNAL') || die();

global $CFG, $OUTPUT, $PAGE, $DB; 

require_login();

$PAGE->set_context(context_system::instance());
$PAGE->set_url('/blocks/guestbook/view.php');
$PAGE->set_pagelayout('standard');
$PAGE->set_heading(get_string('pluginname', 'block_guestbook'));
$PAGE->set_title("guestbook");

//создание экземпляра формы 
$form = new guestbook_form(); 
if($form->is_cancelled()) {
	//перенаправляем на главную страницу гостевой книги 
	$courseurl = new moodle_url('/view.php');
	redirect($courseurl);
} else if($fromform = $form->get_data()) {
	//вызов метода для добавления сообщения
	$engine->add_message($fromform->text);
	//перенаправление на главную страницу
	$url = new moodle_url('/blocks/guestbook/view.php');
	redirect($url);
} else {
	//вывод гостевой книги
	echo $OUTPUT->header();
	$form->display();
	$face->show_messages($engine);
	echo $OUTPUT->footer();
}
	
    

 